package filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterFilter implements Filter {
	protected String encodingChar = null;
	protected FilterConfig config = null;
	public void destroy() {
		this.encodingChar = null;
		this.config = null;
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		if(encodingChar ==null){
		    encodingChar = "utf-8";								
		}
		request.setCharacterEncoding(encodingChar);
		//response.setCharacterEncoding(encodingChar);
		response.setContentType("text/html;charset="+encodingChar);	
		chain.doFilter(request, response);

	}

	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		this.config = filterConfig;
		this.encodingChar = config.getInitParameter("encoding");
	}

}
